package com.example.miiiitia.androiddemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.miiiitia.androiddemo.fragment.FragmentMainActivity;

public class MainActivity extends AppCompatActivity {


    private static final int BTNMARGIN = 5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainLinearLayout);
        mainLayout.setBackgroundResource(R.mipmap.main_activity_background);


        initBtnColumn1();
        initBtnColumn2();
        initBtnColumn3();

    }


    private void initBtnColumn1() {

        LinearLayout layout = (LinearLayout) findViewById(R.id.colum1);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        params.setMargins(MainActivity.BTNMARGIN, MainActivity.BTNMARGIN, MainActivity.BTNMARGIN, MainActivity.BTNMARGIN);


        Button btn1 = new Button(MainActivity.this);
        btn1.setText("Fragment");
        btn1.setBackgroundResource(R.drawable.main_btn_selector);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, FragmentMainActivity.class);
                startActivity(intent);
            }
        });
        layout.addView(btn1, params);

    }


    private void initBtnColumn2() {

        LinearLayout layout = (LinearLayout) findViewById(R.id.colum2);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        params.setMargins(MainActivity.BTNMARGIN, MainActivity.BTNMARGIN, MainActivity.BTNMARGIN, MainActivity.BTNMARGIN);


        Button btn1 = new Button(MainActivity.this);
        btn1.setText("菜单");
        btn1.setBackgroundResource(R.drawable.main_btn_selector);
        layout.addView(btn1, params);

    }

    private void initBtnColumn3() {

        LinearLayout layout = (LinearLayout) findViewById(R.id.colum3);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        params.setMargins(MainActivity.BTNMARGIN, MainActivity.BTNMARGIN, MainActivity.BTNMARGIN, MainActivity.BTNMARGIN);


        Button btn1 = new Button(MainActivity.this);
        btn1.setText("菜单");
        btn1.setBackgroundResource(R.drawable.main_btn_selector);
        layout.addView(btn1, params);

    }

}
